﻿<div class="page-content-wrap">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline tool-btn">
                <button class="layui-btn layui-btn-small layui-btn-normal addBtn-sm hidden-xs" data-url="/Home/EditParent"><i class="layui-icon">&#xe654;</i></button>
                <button class="layui-btn layui-btn-small layui-btn-danger delBtn hidden-xs" data-id="tab" data-url="/Home/deleteparent"><i class="layui-icon">&#xe640;</i></button>
            </div>
        </div>
    </form>
    <div id="table-list" class="layui-form" style="height: 400px;">
        <input type="hidden" id="index" />
        <table id="tab"></table>
    </div>
</div>
@section script{
<script>
		$("#tab").datagrid({
			idField: 'parentid',
        //singleSelect: false,
        //rownumbers: true,
        //pagePosition: 'bottom',
        //pagination: true,//分页
        //pageSize: 10,//每页显示条数
        //pageList: [10, 15, 20, 30, 50, 100], //调整每页显示条数
        fit: true,//宽高跟随父面板
        fitColumns: true,//水平滚动条
        nowrap: false,//折行显示
        columns: [[
            {field:'check',checkbox:true, width: 100, align: 'center' },
            { field: 'id', title: '主模块编号', width: 180, align: 'center' },
            { field: 'pname', title: '主模块名称', width: 180, align: 'center' },
            {field:'edit',title:'编辑',width:100,align:'center',
	            formatter: function(value,row,index){
					return '<button class="layui-btn layui-btn-mini layui-btn-normal edit-btn-sm" data-id="'+row.id+'" data-url="/Home/UpdateParent"><i class="layui-icon">&#xe642;</i></button>';
				}
            }
        ]],
        url: '/Home/parenttable',
		})
		layui.use(['jquery', 'layer', 'dialog','checkbox'], function() {
			var $ = layui.jquery;
		});
		//顶部批量删除
		$('.delBtn').click(function () {
		    var id = "#" + $(this).attr("data-id");
		    var $table = $(id).datagrid('getChecked');
		    var no = new Array();
		    for (var i = 0; i < $table.length; i++) {
		        if (i == 0) {
		            no = "no=" + $table[i].id;
		        } else {
		            no += "&no=" + $table[i].id;
		        }
		    }
		    var url = $(this).attr('data-url');
		    layer.confirm('您确定要删除选中项?', function (index) {
		        //do something
		        $.get(url, no, function (data) {
		            layer.msg(data);
		            location.reload();
		        })
		        layer.close(index);
		    });
		    return false;
		});
		//顶部添加sm
		$('.addBtn-sm').click(function () {
		    var url = $(this).attr('data-url');
		    //将iframeObj传递给父级窗口,执行操作完成刷新
		    layer.open({
		        type: 2,
		        area: ['400px', '200px'],
		        content: url, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		        cancel:function(){
		            location.reload();
		        }
		    });
		    
		    return false;
		});
		$('#table-list').on('click', '.edit-btn-sm', function () {
		    var That = $(this);
		    var id = That.attr('data-id');
		    var url = That.attr('data-url');
		    //将iframeObj传递给父级窗口
		    layer.open({
		        type: 2,
		        area: ['400px', '200px'],
		        content: url + "?id=" + id, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		        cancel: function () {
		            location.reload();
		        }
		    });
		    return false;
		})
</script>
}

